﻿(function (e) {
    "use strict";
    var t = e.jQuery,
		n = e.qh360cp,
		r = e._;
    n.pages.init = function () {
        n.ui.select({
            sel: "#his_issue",
            callback: n.pages.search
        });
        var e = t(".pred-list");
        e.on("click", ".ico-notop", function () {//点击置顶
            var e = t(this),
				r, i, s;
            e.toggleClass("ico-top"),
            r = n.store.get("ssq_code"),
            i = e.parents("tr").attr("mid"),
            s = new RegExp(";?" + i, "gi"),
            e.hasClass("ico-top") ? n.store.set("ssq_code", r ? r + ";" + i : i) : (r = (r || "").replace(s, ""), n.store.set("ssq_code", r)), n.pages.sort()
        }),
        //取消置顶
        t(".model:eq(0)").on("click", "#clear_top", function (e) {
            e.preventDefault(), n.store.set("ssq_code", ""), n.pages.sort()
        }),
        //查看详细页
        e.on("click", ".seecode", function (e) {
            e.preventDefault();
            var r = t(this);
            n.pages.mediaID = r.parents("tr").attr("mid");
            var i = {
                lotid: n.lottery.lott_type_id.ssq,
                mediaid: n.pages.mediaID,
                orderby: 0,
                pageno: 1,
                pagesize: 10,
                rt: Math.random()
            },
				s = "/Media/detail?" + t.param(i);
            t.getJSON(s, function (e) {
                t.trim(e.ListHtml) != "" ? (n.lightBox.show({
                    html: e.ListHtml,
                    cancel_sel: ".close"
                }), n.pages.page()) : n.lightBox.alert({
                    content: "\u6682\u65e0\u6570\u636e"
                })
            })
        }),
        //切换排序方式
        t(".forcast").on("change", function () {
            n.pages.search()
        }),
        t("body").on("change", ":radio[name=autobuy_record]", function () {
            n.pages.get_page()
        })
    },
    n.pages.page = function () {
        var e = t("#autobuy_page .pagesub");
        n.ui.pages({
            box: e.selector,
            page_no: e.data("pageno") || e.attr("pageno"),
            page_count: e.data("pages") || e.attr("pages"),
            go_page: 0,
            callback: function () {
                n.pages.get_page()
            }
        })
    },
    n.pages.get_page = function () {
        var e = t("#autobuy_page .pagesub"),
			r = e.data("pageno") || 1,
			i = "/Media/detaillist?lotid=220051&mediaid=" + n.pages.mediaID + "&orderby=" + t(":radio[name=autobuy_record]:checked").val() + "&pageno=" + r + "&t=" + +(new Date);
        t.ajax({
            url: i,
            dataType: "json",
            success: function (r) {
                r && (t("#autobuy_list").html(r.ListHtml), e.data("pageno", r.pageno || ""), e.data("pages", r.pages || ""), n.pages.page())
            },
            error: function () { }
        })
    },
    n.pages.search = function () {
        var e = t(".model:eq(0)"),
			r = e.find(":radio:checked").attr("order"),
			i = {
			    lotid: n.lottery.lott_type_id.ssq,
			    issue: t("#his_issue").val(),
			    orderby: r,
			    rt: Math.random()
			},
			s = "/Media/getlist?" + t.param(i);
        t.getJSON(s, function (e) {
            e && typeof e == "object" ? (t("#row_list").html(e.ListHtml), t("#statusHtml").html(e.BonusHtml + e.StatHtml), t("#cur_issue").html(i.issue), n.pages.sort()) : n.lightBox.alert({
                content: "\u65e0\u8fd4\u56de\u503c"
            })
        })
    },
    n.pages.sort = function () {
        var e = [],
			r = [],
			i = t("#row_list"),
			s, o, u, a, f = (n.store.get("ssq_code") || "").split(";");
        i.find("tr").each(function (n, i) {
            s = t(i), o = s.attr("mid"), u = s.attr("row"), a = t.inArray(o, f), a > -1 ? e[a] = '<tr row="' + s.attr("row") + '" mid="' + o + '" class="top">' + s.html() + "</tr>" : r[u] = '<tr row="' + s.attr("row") + '" mid="' + o + '">' + s.html() + "</tr>"
        }), i.html(e.join("").replace(/ico-notop|ico-notop ico-top/g, "ico-notop ico-top") + r.join("").replace(/ico-top/g, "")), i.find("tr:not(.top):odd").addClass("odd"), t(".top").length > 0 ? t("#clear_top").show() : t("#clear_top").hide()
    },
    n.pages.init(), n.pages.sort()
})(window);